package tcu.iot.gasmanage.mapper.provider;

import tcu.iot.gasmanage.entity.equipment.EquipmentQuery;
import tcu.iot.gasmanage.entity.export.ExportQuery;

public class ExportProvider {

    private void CreateSql(ExportQuery exportQuery, StringBuffer sql) {
        //通过判断传入的实体，相应字段是否为空，来进行sql语句的编写
        if (!exportQuery.getProvince().equals(""))
            sql.append("AND province= '").append(exportQuery.getProvince()).append("' ");
        if (!exportQuery.getRegion().equals(""))
            sql.append("AND region= '").append(exportQuery.getRegion()).append("' ");
        if (!exportQuery.getPipeline().equals(""))
            sql.append("AND pipeline= '").append(exportQuery.getPipeline()).append("' ");
        if (!exportQuery.getManagement().equals(""))
            sql.append("AND management= '").append(exportQuery.getManagement()).append("' ");
        if (!exportQuery.getPrincipal().equals(""))
            sql.append("AND principal= '").append(exportQuery.getPrincipal()).append("' ");
        if (!exportQuery.getSite().equals(""))
            sql.append("AND site= '").append(exportQuery.getSite()).append("' ");
    }

    public String SelectEquipmentData(ExportQuery exportQuery) {
        StringBuffer sql = new StringBuffer("SELECT * FROM equipment WHERE 1=1 ");

        CreateSql(exportQuery, sql);

        return sql.toString();

    }

    public String SelectEquipmentList(ExportQuery exportQuery) {
        StringBuffer sql = new StringBuffer("SELECT equipmentNumber FROM equipment WHERE 1=1 ");

        CreateSql(exportQuery, sql);

        return sql.toString();
    }

    public String SelectEquipmentDataCount(ExportQuery exportQuery) {
        StringBuffer sql = new StringBuffer("SELECT count(*) FROM equipment WHERE 1=1 ");

        CreateSql(exportQuery, sql);

        return sql.toString();
    }

}
